package com.redis.service.impl;

import com.redis.entity.TicketDTO;
import com.redis.entity.User;
import com.redis.mapper.UserMapper;
import com.redis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author: Li
 * @Date: 2024/12/16 10:34
 * @Description:
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    
    @Override
    public String login(String phone, String password) {
        User user = userMapper.getUserByPhone(phone);
        // 手机号不存在
        if (user == null) {
            return "手机号未注册，请检查输入";
        }
        // 密码错误
        if (!user.getPassword().equals(password)) {
            return "密码错误";
        }
        return "登录成功";
    }
    
    public String register(String phone, String name, String password, String repassword) {
        User user = userMapper.getUserByPhone(phone);
        if (user != null) {
            return "手机号已被注册";
        }
        if (!password.equals(repassword)) {
            return "两次输入密码不一致";
        }
        user = new User();
        user.setPhone(phone);
        user.setPassword(password);
        if (name != null && !"".equals(name)) {
            user.setName(name);
        } else {
            user.setName("用户" + phone.substring(phone.length() - 4));
        }
        userMapper.registerUser(user);
        return "注册成功";
    }
    
    public List<TicketDTO> getAllTicket(String uid) {
        return userMapper.getAllTicket(uid);
    }
}
